﻿using MediatR;
using W.Purchase.API.Application.Command.ReceivableCommand;
using W.Purchase.Repository.Impl;
using W.Purchase.Repository.Interface;

namespace W.Purchase.API.Application.CommandHandler.ReceivableCommandHandler
{
    public class ReceivableDelRangeCommandHandler : IRequestHandler<ReceivableDelRangeCommand, int>
    {
        private readonly IReceivableRepository _ireceivableRepository;
        public ReceivableDelRangeCommandHandler(IReceivableRepository ireceivableRepository)
        {
            _ireceivableRepository = ireceivableRepository;
        }
        public async Task<int> Handle(ReceivableDelRangeCommand request, CancellationToken cancellationToken)
        {
            var list = await _ireceivableRepository.GetAllAsaync();
            var plist = list.Where(c => request.Ids.Contains(c.ReceivableId)).ToList();
            foreach (var item in plist)
            {
                item.IsDelete = true;
            }
            int n = await _ireceivableRepository.UpdateRangeAsync(plist);
            return n;
        }
    }
}
